<?php

namespace Home\Controller;

use Home\Model\TagModel;
use Home\Model\UserModel;
use Home\Model\ShopModel;

class ShopController extends CommonController {
	public function _initialize() {
		$this->mobileUrl = check_mobile (); // 判断是否移动设备,如果是则跳到wap;如果不是返回wap地址;
		$uid = get_cookie ( 'uid' );
		if ($uid) {
			$user = new UserModel ();
			$this->user = $user->getUserInfo ( $uid );
		} else {
			$this->error ( '请登录后再操作!', '/' );
		}
		$tag = new TagModel ();
		$this->hotTags = $tag->getHotTag ();
	}
	public function register() {
		$shop = new ShopModel ();
		$info = $shop->getInfoForUid ( $this->user ['uid'] );
		if ($info ['id']) {
			$this->error ( '您已经是商家', '/?c=shop&a=admin' );
		}
		$this->display ();
	}
	public function saveData() {
		$shop = new ShopModel ();
		$rs = $shop->saveData ( $_POST, $_POST ['id'], $this->user ['uid'] );
		if ($rs ['status']) {
			$this->success ( '恭喜您操作成功!', '/?c=shop&a=admin' );
		} else {
			$this->error ( $rs ['msg'] );
		}
	}
	public function admin() {
		$shop = new ShopModel ();
		$data ['info'] = $shop->getInfoForUid ( $this->user ['uid'] );
		$this->data = $data;
		$this->display ();
	}
}